package com.SunSoft.PhoneRemoteControl;

import android.content.Context;
import android.content.res.AssetManager;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public final class e extends SQLiteOpenHelper
{
  private static String a = "/data/data/com.SunSoft.PhoneRemoteControl/databases/";
  private static String b = "temp_save.dat";
  private static String c = "tsg_temp.dat";
  private SQLiteDatabase d;
  private final Context e;

  public e(Context paramContext)
  {
    this(paramContext, a + b, '\0');
  }

  private e(Context paramContext, String paramString)
  {
    super(paramContext, paramString, null, 1);
    this.d = null;
    this.e = paramContext;
  }

  private e(Context paramContext, String paramString, byte paramByte)
  {
    this(paramContext, paramString);
  }

  private e(Context paramContext, String paramString, char paramChar)
  {
    this(paramContext, paramString, 0);
  }

  private static String a(int paramInt)
  {
    for (String str = String.valueOf(paramInt); ; str = "0" + str)
      if (str.length() >= 3)
        return str;
  }

  private static boolean b()
  {
    Object localObject1 = null;
    Object localObject2 = a + b;
    try
    {
      localObject2 = SQLiteDatabase.openDatabase((String)localObject2, null, 1);
      localObject1 = localObject2;
      if (localObject1 != null)
        localObject1.close();
      return (localObject1 == null);
    }
    catch (SQLiteException localSQLiteException)
    {
    }
  }

  private void c()
  {
    FileOutputStream localFileOutputStream = new FileOutputStream(a + b);
    int i = 1;
    if (i >= 9)
    {
      localFileOutputStream.close();
      return;
    }
    InputStream localInputStream = this.e.getAssets().open(c + "." + a(i));
    byte[] arrayOfByte = new byte[1024];
    while (true)
    {
      int j;
      while (true)
      {
        j = localInputStream.read(arrayOfByte);
        if (j > 0)
          break;
        localFileOutputStream.flush();
        localInputStream.close();
        i += 1;
      }
      localFileOutputStream.write(arrayOfByte, 0, j);
    }
  }

  public final void a()
  {
    if (!(b()));
    try
    {
      File localFile = new File(a);
      if (!(localFile.exists()))
        localFile.mkdirs();
      localFile = new File(a + b);
      if (localFile.exists())
        localFile.delete();
      SQLiteDatabase.openOrCreateDatabase(localFile, null);
      c();
      return;
    }
    catch (IOException localIOException)
    {
    }
  }

  public final void close()
  {
    monitorenter;
    try
    {
      if (this.d != null)
        this.d.close();
      super.close();
      return;
    }
    finally
    {
      monitorexit;
    }
  }

  public final void onCreate(SQLiteDatabase paramSQLiteDatabase)
  {
  }

  public final void onUpgrade(SQLiteDatabase paramSQLiteDatabase, int paramInt1, int paramInt2)
  {
  }
}